/**
* Created by wust on 2020-07-15 13:54:05.
*/
<template>
	<el-form ref="formModel" :model="formModel" :rules="rules" label-width="120px" style="width:70%;"
	 @submit.native.prevent>
		<el-form-item label="goods_no" prop="goodsNo">
			<el-input v-model="formModel.goodsNo"></el-input>
		</el-form-item>
		<el-form-item label="name" prop="name">
			<el-input v-model="formModel.name"></el-input>
		</el-form-item>
		<el-form-item label="unit_price" prop="unitPrice">
			<el-input v-model="formModel.unitPrice"></el-input>
		</el-form-item>
		<el-form-item label="picture" prop="picture">
			<el-input v-model="formModel.picture"></el-input>
		</el-form-item>
		<el-form-item label="stock" prop="stock">
			<el-input v-model="formModel.stock"></el-input>
		</el-form-item>
		<el-form-item label="description" prop="description">
			<el-input v-model="formModel.description"></el-input>
		</el-form-item>
		<el-form-item label="is_deleted" prop="isDeleted">
			<el-input v-model="formModel.isDeleted"></el-input>
		</el-form-item>

		<el-form-item style="text-align: left;">
			<el-button type="primary" @click="onSubmit('formModel')" :loading="submitting">提交</el-button>
		</el-form-item>
	</el-form>
</template>
<script>
import Vue from 'vue'

export default {
  name: 'goods-create',
  data () {
    return {
      submitting: false,
      formModel: {
        goodsNo: null,
        name: null,
        unitPrice: null,
        picture: null,
        stock: null,
        description: null,
        isDeleted: null

      },
      rules: {}
    }
  },
  methods: {
    onSubmit: function (formData) {
      this.$refs[formData].validate((valid) => {
        if (!valid) {} else {
          this.submitting = true
          Vue.$ajax({
            method: 'post',
            url: Vue.$orderServerURL + '/web/v1/GoodsController',
            data: this.formModel
          }).then(res => {
            this.submitting = false
            if (res.data.flag !== 'SUCCESS') {
              if (!Vue.$isNullOrIsBlankOrIsUndefined(res.data.message)) {
                this.$message({
                  message: res.data.message,
                  type: 'warning'
                })
              }
            } else {
              this.$message({
                message: res.data.message,
                type: 'success'
              })
              this.resetForm('formModel')
            }
          })
        }
      })
    },
    resetForm (formData) {
      this.$refs[formData].resetFields()
    }
  }
}
</script>
